package com.anti.modular.owner.ownerlease.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.commom.pojo.BaseValidatedGroup;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.owner.ownerlease.param.OwnerLeaseParam;
import com.anti.modular.owner.ownerlease.service.OwnerLeaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 業主租約控制器
 *
 * @author anti
 * @date 2021-05-20 14:23:14
 */
@RestController
@RequestMapping("ownerLease")
public class OwnerLeaseController {

    @Resource
    private OwnerLeaseService ownerLeaseService;

    /**
     * 查询業主租約
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @GetMapping("page")
    public Result page(PageParam pageParam, OwnerLeaseParam ownerLeaseParam) {
        return Result.data(ownerLeaseService.page(pageParam,ownerLeaseParam));
    }

    /**
     * 添加業主租約
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @PostMapping("add")
    @BusinessLog(title = "業主租約_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(OwnerLeaseParam.add.class) OwnerLeaseParam ownerLeaseParam) {
            ownerLeaseService.add(ownerLeaseParam);
        return Result.success("新增成功");
    }
    @PostMapping("editYzXx")
    @BusinessLog(title = "業主租約_修改業主信息", opType = LogAnnotionOpTypeEnum.ADD)
    public Result editYzXx(@RequestBody @Validated(OwnerLeaseParam.detail.class) OwnerLeaseParam ownerLeaseParam) {
        ownerLeaseService.editYzXx(ownerLeaseParam);
        return Result.success("修改業主信息成功");
    }
    @PostMapping("editZyZqFy")
    @BusinessLog(title = "業主租約_修改業主周期信息", opType = LogAnnotionOpTypeEnum.ADD)
    public Result editZyZqFy(@RequestBody @Validated(OwnerLeaseParam.detail.class) OwnerLeaseParam ownerLeaseParam) {
        ownerLeaseService.editZyZqFy(ownerLeaseParam);
        return Result.success("修改業主信息成功");
    }
    @PostMapping("editTxxxAndAc")
    @BusinessLog(title = "業主租約_修改業主周期信息", opType = LogAnnotionOpTypeEnum.ADD)
    public Result editTxxxAndAc(@RequestBody @Validated(OwnerLeaseParam.detail.class) OwnerLeaseParam ownerLeaseParam) {
        ownerLeaseService.editTxxxAndAc(ownerLeaseParam);
        return Result.success("修改業主信息成功");
    }

    /**
     * 删除業主租約
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @PostMapping("delete")
    @BusinessLog(title = "業主租約_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(OwnerLeaseParam.delete.class) OwnerLeaseParam ownerLeaseParam) {
            ownerLeaseService.delete(ownerLeaseParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑業主租約
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @PostMapping("edit")
    @BusinessLog(title = "業主租約_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(OwnerLeaseParam.edit.class) OwnerLeaseParam ownerLeaseParam) {
            ownerLeaseService.edit(ownerLeaseParam);
        return Result.success("修改成功");
    }

    @PostMapping("editXz")
    @BusinessLog(title = "業主租約_續租", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editXz(@RequestBody @Validated(OwnerLeaseParam.editXuZu.class) OwnerLeaseParam ownerLeaseParam) {
        ownerLeaseService.editXz(ownerLeaseParam);
        return Result.success("修改成功");
    }

    @PostMapping("editTuiZu")
    @BusinessLog(title = "業主租約_退租", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editTuiZu(@RequestBody @Validated(OwnerLeaseParam.editTuiZu.class) OwnerLeaseParam ownerLeaseParam) {
        ownerLeaseService.editTuiZu(ownerLeaseParam);
        return Result.success("修改成功");
    }

    /**
     * 查看業主租約
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @GetMapping("detail")
    public Result detail(@Validated(OwnerLeaseParam.detail.class) OwnerLeaseParam ownerLeaseParam) {
        return Result.data(ownerLeaseService.detail(ownerLeaseParam));
    }

    @GetMapping("detailById/{id}")
    public Result detail(@PathVariable(name = "id") Long id) {
        OwnerLeaseParam ownerLeaseParam=new OwnerLeaseParam();
        ownerLeaseParam.setId(id);
        return Result.data(ownerLeaseService.detail(ownerLeaseParam));
    }

    @GetMapping("detailForEdit/{leaseId}")
    public Result detailForEdit(@PathVariable(name = "leaseId") Long leaseId) {
        return Result.data(ownerLeaseService.detailForEdit(leaseId));
    }
    /**
     * 業主租約列表
     *
     * @author anti
     * @date 2021-05-20 14:23:14
     */
    @GetMapping("list")
    public Result list(OwnerLeaseParam ownerLeaseParam) {
        return Result.data(ownerLeaseService.list(ownerLeaseParam));
    }

}
